package org.activequant.tradesystem.ib;

import org.activequant.broker.IBroker;
import org.activequant.util.messaging.ISimpleMessagingService;
import org.apache.log4j.Logger;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.annotation.ExternalBean;

import com.ib.algokit.TraderProxy;
/**
 * Configuration annotated<br/>
 * An abstract class.
 * @author Dimitar
 *
 */
@Configuration
public abstract class TradeProxyConfig {
	
	private final Logger log = Logger.getLogger(getClass());

	/**
	 * ExternalBean<br/>
	 * protected abstract IBroker broker();
	 * @return
	 */
	@ExternalBean
	protected abstract IBroker broker();

	@Bean
	protected IPositionService positionService() {
		SimplePositionService positionService = new SimplePositionService(broker());
		positionService.setTrailingDistance(2.5);
		positionService.setMessengerService(new ISimpleMessagingService() {
			public void sendMessage(String subj, String body) {
				log.info("***\tSubject: " + subj);
				log.info("***\t" + body);
			}
		});
		return positionService;
	}
	/**
	 * Bean<br/>
	 * @return
	 */
	@Bean
	public Object system() {
		TraderProxy tp = new TraderProxy();
		// system2.setMessenger(messenger);

		return tp;
	}
}
